import { request } from "@umijs/max";

/** 服务商用户注册*/
export async function register(options?: { [key: string]: any }) {
  return request<Record<string, any>>(`${API_EXP}/api/supplier-users`, {
    method: 'POST',
    data:(options || {}),
  });
}

/** 查询服务商产品 */
export async function page(
  params: {
    // query
    current: string;
    size:string;
    productName?:string;
    industry?:string;
    status?:string;
    supplierId?:string;
    priceMin?:string;
    priceMax?:string;
  },
  options?: { [key: string]: any },
) {
  return request<any>(`${API_EXP}/api/supplier-products/page`, {
    method: 'GET',
    params: {
      ...params,
    },
    ...(options || {}),
  });
}

/** 查询服务商账号 */
export async function pageUsers(
  params: {
    // query
    current: string;
    size:string;
    productName?:string;
    fwslx?:string;
    status?:string;
  },
  options?: { [key: string]: any },
) {
  return request<any>(`${API_EXP}/api/supplier-users/page`, {
    method: 'GET',
    params: {
      ...params,
    },
    ...(options || {}),
  });
}

/** 删除服务商 */
export async function removeUsers(
  params: {
    // query
    id: string;
  },
  options?: { [key: string]: any },
) {
  return request<any>(`${API_EXP}/api/supplier-users/remove`, {
    method: 'DELETE',
    params: {
      ...params,
    },
    ...(options || {}),
  });
}

/** 更新服务商用户*/
export async function update(options?: { [key: string]: any }) {
  return request<Record<string, any>>(`${API_EXP}/api/supplier-users/update`, {
    method: 'PUT',
    data:(options || {}),
  });
}

/** 服务商新增产品*/
export async function addService(options?: { [key: string]: any }) {
  return request<Record<string, any>>(`${API_EXP}/api/supplier-products/add`, {
    method: 'POST',
    data:(options || {}),
  });
}


/** 查询服务商产品列表 */
export async function productInfos(
  params: {
    // query
    supplierId:string
    current:string
    size:string
  },
  options?: { [key: string]: any },
) {
  return request<any>(`${API_EXP}/api/supplier-products/supplier/info`, {
    method: 'GET',
    params: {
      ...params,
    },
    ...(options || {}),
  });

}

/** 服务商用户修改密码*/
export async function servicePass(options?: { [key: string]: any }) {
  return request<Record<string, any>>(`${API_EXP}/api/supplier-users/update/pass`, {
    method: 'PUT',
    data:(options || {}),
  });
}

/** 删除服务商产品 */
export async function removeProduct(
  params: {
    // query
    id: string;
  },
  options?: { [key: string]: any },
) {
  return request<any>(`${API_EXP}/api/supplier-products/remove`, {
    method: 'DELETE',
    params: {
      ...params,
    },
    ...(options || {}),
  });
}

/** 更新服务商产品*/
export async function updateProduct(options?: { [key: string]: any }) {
  return request<Record<string, any>>(`${API_EXP}/api/supplier-products/update`, {
    method: 'PUT',
    data:(options || {}),
  });
}

/** 审核产品*/
export async function auditProduct(options?: { [key: string]: any }) {
  return request<Record<string, any>>(`${API_EXP}/api/supplier-products/audit`, {
    method: 'PUT',
    data:(options || {}),
  });
}

/** 政府审核产品*/
export async function govermentAuditProduct(options?: { [key: string]: any }) {
  return request<Record<string, any>>(`${API_EXP}/api/supplier-product-audit/audit`, {
    method: 'PUT',
    data:(options || {}),
  });
}

/** 政府查询服务商产品 */
export async function govermentPage(
  params: {
    // query
    current: string;
    size:string;
    productName?:string;
    auditStatus?:string;
  },
  options?: { [key: string]: any },
) {
  return request<any>(`${API_EXP}/api/supplier-product-audit/page`, {
    method: 'GET',
    params: {
      ...params,
    },
    ...(options || {}),
  });
}

/** 政府查询服务商产品进度 */
export async function productProcess(
  params: {
    // query
  },
  options?: { [key: string]: any },
) {
  return request<any>(`${API_EXP}/api/supplier-products/progress`, {
    method: 'GET',
    params: {
      ...params,
    },
    ...(options || {}),
  });
}

/** 服务商第一步保存*/
// export async function govermentAuditProduct(options?: { [key: string]: any }) {
//   return request<Record<string, any>>(`${API_EXP}/api/supplier-product-audit/audit`, {
//     method: 'PUT',
//     data:(options || {}),
//   });
// }

/** 政府点击新增按钮新增服务商*/
export async function govermentAddService(options?: { [key: string]: any }) {
  return request<Record<string, any>>(`${API_EXP}/api/supplier-users/add`, {
    method: 'POST',
    data:(options || {}),
  });
}

/** 上传服务商名单文件并获取文件 */
export async function importFile(file: any) {
  const formData = new FormData();
  formData.append('file', file); // 'file' 需与后端接收文件的参数名一致

  return request<any>('/api/supplier-users/import', { // 替换为你的文件上传接口地址
    method: 'POST',
    data: formData,
    headers: {
      'Content-Type': 'multipart/form-data',
    },
  });
}